Ext.namespace("Ext.viz.DomQuery");

Ext.viz.DomQuery = {
    select : function (path,root ,ns) {
        try {
            if(window.ActiveXObject){
                   return root.selectNodes(path);
               }
               else {
                  var oXpe = new XPathEvaluator();
                if(ns)
                      var oNsResolver = ns;
                  else
                    var oNsResolver = oXpe.createNSResolver(root.ownerDocument == null ? root.documentElement : root.ownerDocument.documentElement);
                var oResult = oXpe.evaluate(path, root, oNsResolver, 0, null);
                var aFound = [];
                var oRes;
                while (oRes = oResult.iterateNext()){
                    aFound.push(oRes);
                }
                return aFound;                          
               }
        }
        catch(e) {
        }
    }, 

    selectValue : function (path, root , ns) {
        var res = Ext.viz.DomQuery.select(path , root , ns);
        if (res)
            return res[0].value;
    },

    selectNumber : this.selectValue,

    selectNode : function (path, root , ns) {
        var res = Ext.viz.DomQuery.select(path , root , ns);
        if (res)
            return res[0];
    },

    selectNodeText : function (path, root , ns) {
        // look for 'text' property for IE and 'textContent' for Mozilla
        var res = Ext.viz.DomQuery.selectNode(path, root, ns);
        if(res) {
            if(window.ActiveXObject)
                return res.text;
            else
                return res.textContent;
        }
    }
}; 